<?php

require('config.php');
@include('custom.php');
require('libraries.php');

$dir = $_POST['dir'];

echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";

$response = array();
if ($dir === '/') {
	$getDirs = $GLOBALS['config']['directories'];
	foreach ($getDirs as $dir) {
		echo '<li class="directory collapsed"><a href="#" rel="' . htmlentities($dir) . '/">' . htmlentities(basename($dir)) . '</a></li>' . "\n";

		$response['/'][] = array(basename($dir), $dir, true);
	}
} else {
	$files = '';

	$getDirs = array($dir);
	foreach ($getDirs as $dir) {
		$dirs = scandir($dir);
		$response[$dir] = array();
		foreach ($dirs as $subDir) {
			if ($subDir != '.' && $subDir != '..' && ($subDir != '.svn' || $GLOBALS['config']['sourceControl'] != 'svn')) {
				$path = $dir . $subDir;
				$info = pathinfo($path);
				$isDir = is_dir($path);

				$out = '<li class="' . ($isDir ? 'directory collapsed' : 'file ext_' . $info['extension']) . '"><a href="#" rel="' . htmlentities($path) . '' . ($isDir ? '/' : '') . '">' . htmlentities($subDir) . '</a></li>' . "\n";
				if ($isDir) {
					echo $out;
				} else {
					$files .= $out;
				}
			}
		}
	}

	echo $files;
}

echo "</ul>";